package com.xxtx.trade.web.userCenter;

import com.xxtx.trade.common.util.model.Result;
import com.xxtx.trade.sysUser.dto.BaiDuInfoDto;
import com.xxtx.trade.sysUser.dto.TradeSysRoleDto;
import com.xxtx.trade.sysUser.service.TradeSysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api/v1/xxtx/baidu")
public class SysBaiDuController {

    @Autowired
    private TradeSysUserService tradeSysUserService;

    /*
    * 百度数据入口
    * */
    @RequestMapping(value = "/get/dianji/zj", method = RequestMethod.GET)
    public Result GetDianJiBaiDu(HttpServletResponse response, HttpServletRequest request){
        Result<Object> result = new Result<>();
        BaiDuInfoDto dto = new BaiDuInfoDto();
        String myName = request.getParameter("myName");
        if (myName==null || myName.equals("")){
            result.setMessage("no urlName");
            return result;
        }
        dto.setUrlName(myName);

        String aid = request.getParameter("aid");
        if (aid == null)aid="";
        dto.setAid(aid);

        String pid = request.getParameter("pid");
        if (pid == null)pid="";
        dto.setPid(pid);

        String uid = request.getParameter("uid");
        if (uid == null)uid="";
        dto.setUid(uid);

        String userid = request.getParameter("userid");
        if (userid == null)userid="";
        dto.setUserid(userid);

        String click_id = request.getParameter("click_id");
        if (click_id == null)click_id="";
        dto.setClick_id(click_id);

        String idfa = request.getParameter("idfa");
        if (idfa == null)idfa="";
        dto.setIdfa(idfa);

        String imei_md5 = request.getParameter("imei_md5");
        if (imei_md5 == null)imei_md5="";
        dto.setImei_md5(imei_md5);

        String androidid = request.getParameter("androidid");
        if (androidid == null)androidid="";
        dto.setAndroidid(androidid);

        String androidid_md5 = request.getParameter("androidid_md5");
        if (androidid_md5 == null)androidid_md5="";
        dto.setAndroidid_md5(androidid_md5);

        String ip = request.getParameter("ip");
        if (ip == null)ip="";
        dto.setIp(ip);

        String ua = request.getParameter("ua");
        if (ua == null){
            ua="";
        } else {
            if (ua.length()>100){
                ua = ua.substring(0, 100);
            }
        }
        dto.setUa(ua);

        String os = request.getParameter("os");
        if (os == null)os="";
        dto.setOs(os);

        String ts = request.getParameter("ts");
        if (ts == null)ts="";
        dto.setTs(ts);

        String ext_info = request.getParameter("ext_info");
        if (ext_info == null){
            ext_info="";
        } else {
            if (ext_info.length()>100){
                ext_info = ext_info.substring(0, 100);
            }
        }
        dto.setExt_info(ext_info);

        String mac_md5 = request.getParameter("mac_md5");
        if (mac_md5 == null)mac_md5="";
        dto.setMac_md5(mac_md5);

        String mac = request.getParameter("mac");
        if (mac == null)mac="";
        dto.setMac(mac);

        String oaid = request.getParameter("oaid");
        if (oaid == null)oaid="";
        dto.setOaid(oaid);

        String oaid_md5 = request.getParameter("oaid_md5");
        if (oaid_md5 == null)oaid_md5="";
        dto.setOaid_md5(oaid_md5);

        String comb_id = request.getParameter("comb_id");
        if (comb_id == null)comb_id="";
        dto.setComb_id(comb_id);

        String size = request.getParameter("size");
        if (size == null)size="";
        dto.setSize(size);

        String deeplink_url = request.getParameter("deeplink_url");
        if (deeplink_url == null){
            deeplink_url="";
        } else {
            if (deeplink_url.length()>100){
                deeplink_url = deeplink_url.substring(0, 100);
            }
        }
        dto.setDeeplink_url(deeplink_url);

        String bd_vid = request.getParameter("bd_vid");
        if (bd_vid == null){
            bd_vid="";
        }else {
            if (bd_vid.length()>100){
                bd_vid = bd_vid.substring(0, 100);
            }
        }
        dto.setBd_vid(bd_vid);

        String wordid = request.getParameter("wordid");
        if (wordid == null)wordid="";
        dto.setWordid(wordid);

        String productid = request.getParameter("productid");
        if (productid == null)productid="";
        dto.setProductid(productid);

        tradeSysUserService.insertBaiDuDatas(dto);
        return result;
    }

    /**
     * 按权限查看数据
     * */
    @RequestMapping(value = "/list/permissionInfo", method = RequestMethod.POST)
    public Result permissionBaiduListInfo(@RequestBody TradeSysRoleDto tradeSysRoleDto){
        return tradeSysUserService.baiduPermissionInfoList(tradeSysRoleDto);
    }

    @RequestMapping(value = "/permissionList/all", method = RequestMethod.POST)
    public Result permissionListAll(@RequestBody TradeSysRoleDto tradeSysRoleDto){
        return tradeSysUserService.selectPermissionBaiduUrls(tradeSysRoleDto);
    }

}
